package com.ptu.service.impl;


import com.ptu.entity.InCome;
import com.ptu.entity.PageTools;
import com.ptu.mapper.InComeMapper;
import com.ptu.service.InComeService;
import com.ptu.util.DBUtil;

import java.util.Date;
import java.util.List;

public class InComeServiceImpl implements InComeService {

    @Override
    public int addInC(InCome inc) {
        InComeMapper mapper = DBUtil.getSqlSession().getMapper(InComeMapper.class);
        int insert = mapper.insert(inc);
        DBUtil.closeAll();
        return insert;
    }

//查询多个
    @Override
    public List<InCome> findInCMore( Date icdate1, Date icdate2, String ictype) {
        InComeMapper mapper = DBUtil.getSqlSession().getMapper(InComeMapper.class);
        List<InCome> inComes = mapper.selectInCMore(icdate1, icdate2, ictype);
        DBUtil.closeAll();
        return inComes;
    }
//删除
    @Override
    public int removeInC(Integer icid) {
        InComeMapper mapper = DBUtil.getSqlSession().getMapper(InComeMapper.class);
        int i = mapper.delInC(icid);
        DBUtil.closeAll();
        return i;
    }
//分页
    @Override
    public PageTools<InCome> findInCAll(int pageSize, int pageNumber) {
        InComeMapper mapper = DBUtil.getSqlSession().getMapper(InComeMapper.class);
        PageTools<InCome> pageTools = new PageTools<>();
        pageTools.setPageNumber(pageNumber);
        pageTools.setPageSize(pageSize);
        int pageStart = pageSize*(pageNumber-1);
        List<InCome> inComes= mapper.selectPage2(pageSize, pageStart);
        int total = mapper.selectCount2();
        pageTools.setTotal(total);
        pageTools.setList(inComes);
        DBUtil.closeAll();
        return pageTools;
    }
//查询单个
    @Override
    public InCome findInCByInCid(Integer icid) {
        InComeMapper mapper = DBUtil.getSqlSession().getMapper(InComeMapper.class);
        InCome inc = mapper.findInCByInCid(icid);
        DBUtil.closeAll();
        return inc;
    }
//修改
    @Override
    public int changeInC(InCome inc) {
        InComeMapper mapper = DBUtil.getSqlSession().getMapper(InComeMapper.class);
        int update = mapper.update(inc);
        DBUtil.closeAll();
        return update;
    }

    @Override
    public int findAmount(String ictype) {
        InComeMapper mapper = DBUtil.getSqlSession().getMapper(InComeMapper.class);
        int amount = mapper.selectAmount(ictype);
        DBUtil.closeAll();
        return amount;
    }


}
